package top.api.controller;

import cn.dev33.satoken.annotation.SaCheckRole;
import io.swagger.annotations.ApiOperation;
import lombok.RequiredArgsConstructor;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.*;
import top.api.common.ResUlt;
import top.api.domain.dto.PageDto;
import top.api.domain.pojo.Class;
import top.api.domain.pojo.Course;
import top.api.service.CourseService;
import top.api.service.impl.CourseServiceImpl;

import java.util.List;

@RestController
@RequestMapping("/course")
@RequiredArgsConstructor
public class CourseController {

    private  final CourseServiceImpl courseService;
    @GetMapping("/list")
//    @SaCheckRole("admin")
    @ApiOperation("分页查询")
    public ResUlt<?> listPage(PageDto pageDto, Integer id, String classname){
        return courseService.listPage(pageDto,id,classname);
    }


    @PostMapping
    @SaCheckRole("admin")
    @ApiOperation("添加课程")
    public ResUlt<?> add(@RequestBody Course course){
        return courseService.add(course);
    }


    @GetMapping("{id}")
    @ApiOperation("获取课程")
    public ResUlt<?> getOne(@PathVariable Integer id){
        return courseService.getOne(id);
    }

    @DeleteMapping("{id}")
    @SaCheckRole("admin")
    @ApiOperation("删除课程")
    public ResUlt<?> delete(@PathVariable List id){
        return courseService.delete(id);
    }

    @PutMapping
    @SaCheckRole("admin")
    @ApiOperation("更新课程")
    public ResUlt<?> updateUser(@RequestBody Course course){
        return courseService.changeClass(course);
    }

    @PutMapping("/status")
    @SaCheckRole("admin")
    @ApiOperation("更新课程状态")
    public ResUlt<?> changeStatus(@RequestBody Course course) {
        return courseService.changeStatus(course);
    }
}
